package com.yuqih.common.dto;

import com.fasterxml.jackson.annotation.JsonIgnore;

public class PageMetadata {

	private Integer pageNo;
	private Integer pageSize;
	private String sort;
	private String direction;
	
	// _row_from 从0开始  oracle  >
	// _row_to  _row_from + pageSize oracle <=
	
	@JsonIgnore
	public boolean getNeedPage() {
		if (pageNo == null || pageSize == null) {
			return false;
		}
		return true;
	}
	
	@JsonIgnore
	public int getStartRow() {
		return (pageNo - 1) * pageSize;
	}
	
	@JsonIgnore
	public int getEndRow() {
		return pageNo * pageSize - 1;
	}

	/**
	 * @return the pageNo
	 */
	@JsonIgnore
	public Integer getPageNo() {
		return pageNo;
	}

	/**
	 * @param pageNo
	 *            the pageNo to set
	 */
	@JsonIgnore
	public void setPageNo(Integer pageNo) {
		this.pageNo = pageNo;
	}

	/**
	 * @return the pageSize
	 */
	@JsonIgnore
	public Integer getPageSize() {
		return pageSize;
	}

	/**
	 * @param pageSize
	 *            the pageSize to set
	 */
	@JsonIgnore
	public void setPageSize(Integer pageSize) {
		this.pageSize = pageSize;
	}

	/**
	 * @return the sort
	 */
	@JsonIgnore
	public String getSort() {
		return sort;
	}

	/**
	 * @param sort
	 *            the sort to set
	 */
	@JsonIgnore
	public void setSort(String sort) {
		this.sort = sort;
	}

	/**
	 * @return the direction
	 */
	@JsonIgnore
	public String getDirection() {
		return direction;
	}

	/**
	 * @param direction
	 *            the direction to set
	 */
	@JsonIgnore
	public void setDirection(String direction) {
		this.direction = direction;
	}

	/**
	 * @return the _pageNo
	 */
	public Integer get_pageNo() {
		return pageNo;
	}

	/**
	 * @param _pageNo
	 *            the _pageNo to set
	 */
	public void set_pageNo(Integer _pageNo) {
		this.pageNo = _pageNo;
	}

	/**
	 * @return the _pageSize
	 */
	public Integer get_pageSize() {
		return pageSize;
	}

	/**
	 * @param _pageSize
	 *            the _pageSize to set
	 */
	public void set_pageSize(Integer _pageSize) {
		this.pageSize = _pageSize;
	}

	/**
	 * @return the _sort
	 */
	public String get_sort() {
		return sort;
	}

	/**
	 * @param _sort
	 *            the _sort to set
	 */
	public void set_sort(String _sort) {
		this.sort = _sort;
	}

	/**
	 * @return the _direction
	 */
	public String get_direction() {
		return direction;
	}

	/**
	 * @param _direction
	 *            the _direction to set
	 */
	public void set_direction(String _direction) {
		this.direction = _direction;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((direction == null) ? 0 : direction.hashCode());
		result = prime * result + ((pageNo == null) ? 0 : pageNo.hashCode());
		result = prime * result + ((pageSize == null) ? 0 : pageSize.hashCode());
		result = prime * result + ((sort == null) ? 0 : sort.hashCode());
		return result;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		PageMetadata other = (PageMetadata) obj;
		if (direction == null) {
			if (other.direction != null)
				return false;
		} else if (!direction.equals(other.direction))
			return false;
		if (pageNo == null) {
			if (other.pageNo != null)
				return false;
		} else if (!pageNo.equals(other.pageNo))
			return false;
		if (pageSize == null) {
			if (other.pageSize != null)
				return false;
		} else if (!pageSize.equals(other.pageSize))
			return false;
		if (sort == null) {
			if (other.sort != null)
				return false;
		} else if (!sort.equals(other.sort))
			return false;
		return true;
	}

	
}
